package com.fit.entities;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.Validate;

@Entity
@Table(name = "offer_items")
@AssociationOverrides({
		@AssociationOverride(name = "pk.transportOffer", joinColumns = @JoinColumn(name = "transport_offer_id")),
		@AssociationOverride(name = "pk.destinationOffer", joinColumns = @JoinColumn(name = "destination_offer_id")),
		@AssociationOverride(name = "pk.arrangement", joinColumns = @JoinColumn(name = "arrangement_id")) })
public class OfferItem {

	@EmbeddedId
	private OfferItemPk pk = new OfferItemPk();
	@Validate("required")
	@Column(name = "arrangement_totalPrice", nullable = false)
	private double totalPrice;

	public OfferItemPk getPk() {
		return pk;
	}

	public void setPk(OfferItemPk pk) {
		this.pk = pk;
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public void setTransportOffer(TransportOffer tf) {
		getPk().setTransportOffer(tf);
	}

	@Transient
	public TransportOffer getTransportOffer() {
		return getPk().getTransportOffer();
	}

	public void setDestinationOffer(DestinationOffer df) {
		getPk().setDestinationOffer(df);
	}

	@Transient
	public DestinationOffer getDestinationOffer() {
		return getPk().getDestinationOffer();
	}

	public void setArrangement(Arrangement ar) {
		getPk().setArrangement(ar);
	}

	@Transient
	public Arrangement getArrangement() {
		return getPk().getArrangement();
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		OfferItem that = (OfferItem) o;

		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;

		return true;
	}

}
